﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BenevolentSun
{
    class SplashScreen : Screen
    {

        TextField bss;

        Tween alphaTween;

        public override void LoadContent()
        {
            SpriteFont font = Content.Load<SpriteFont>("Fonts/Alpha Male Modern 85");
            bss = new TextField("Benevolent Sun Studios", font);
            bss.Color = Color.White;
            bss.Color.A = 0;

            bss.Position = new Vector2(1280f / 2f, 720f / 2f);
            bss.AlignH = AlignH.Center;
            bss.AlignV = AlignV.Center;

            alphaTween = new Tween(0f, 255f, 0.75, Tween.LoopType.None);

            base.LoadContent();
        }

        public override void HandleInput()
        {
            if (ActionMap.Skip)
            {
                NextScreen();
            }

            base.HandleInput();
        }

        private void NextScreen()
        {
            ScreenManager.AddScreen(new IntroScreen());
            ExitScreen();
        }

        public override void Update(GameTime gameTime, bool isFocusAvailable, bool isOccluded)
        {
            alphaTween.Update(gameTime);
            bss.Color.A = (byte)alphaTween.Value;
            if (alphaTween.IsFinished)
            {
                if (alphaTween.Start == 0f)
                {
                    alphaTween = new Tween(255f, 255f, 1.5, Tween.LoopType.None);
                }
                else if (alphaTween.End == 255f)
                {
                    alphaTween = new Tween(255f, 0f, 0.75, Tween.LoopType.None);
                }
                else
                {
                    NextScreen();
                }
            }
               

            base.Update(gameTime, isFocusAvailable, isOccluded);
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch.Begin();
            bss.Draw(SpriteBatch);
            SpriteBatch.End();
            base.Draw(gameTime);
        }

    }
}
